<template>
  <div id="mine">
    <h1>个人中心</h1>
    <div class="header">
      <img src="/img/touxiang.png" alt="" class='photo'>
      <div class="right">
        <p>爱新觉罗 玄烨</p>
        <p>成都市高新区名著司南5栋...</p>
      </div>
      <img src="/img/xiaoxi.png" alt="" class='mess'>
    </div>

    <div class="sore">
      <div class="invite">
        <span>累计邀请</span>
        <span><i>127</i> / 人</span>
      </div>
      <div class="jifen">
        <span>累计积分</span>
        <span><i>2650</i></span>
      </div>
    </div>

    <div class="about">
      <router-link to="/grade">
      <div>
        <img src="/img/minejifen.png" alt="">
        <span>我的积分</span>
      </div>
      </router-link>
      <router-link to="/medal">
      <div>
        <img src="/img/minexun.png" alt="">
        <span>我的勋章</span>
      </div>
      </router-link>
      <router-link to="/order">
      <div>
        <img src="/img/mineorder.png" alt="">
        <span>我的订单</span>
      </div>
      </router-link>
      
    </div>
    <div class="show">
      <app-scroll class="content">
        <h6>我的兑换</h6>
          <li v-for="item in goods" :key="item.item.id">
                <img :src="item.item.airImage" alt="" />
                <div class="introduction">
                  <p>{{ item.item.title }}</p>
                  <!-- <h1>限量{{ item.item.limit }}</h1> -->
                  <!-- <h2>{{ item.item.has }} 人已领</h2> -->
                  <h3>{{ item.item.grade }} 积分</h3>
                  <h4 @click="cancle(item.item.id)">删除</h4>
                </div>
          </li>
          
      </app-scroll>
      
    </div>
    <h5>所需积分: <span>{{total}}分</span><i ref="duihuan">兑换</i></h5>
  </div>
</template>

<script>
import axios from "axios";
export default {
    data(){
      return {
        goods:[],
        total:0,
      }
    },
    methods:{
      async requestShopMsg() {
        const {
          data: { data },
        } = await axios.get("/data/grade.json");
        // console.log(ms)
        // this.goods = data;
         data.forEach(item=>{
            JSON.parse(localStorage.getItem("gradeid")).forEach(item1=>{
                if(item.id===item1.id){
                    this.goods.push({item,num:item1.num});  
            }
            })
            
            
        });
        this.goods.forEach(item=>{
            this.total+=item.item.grade
        })
        if(this.total>2650){
          this.$refs.duihuan.style.background = "#ccc"
        }else{
          this.$refs.duihuan.style.background = "#FA7268"
        }
        // console.log(this.goods)
      },
      cancle(id){
        var msg = JSON.parse(localStorage.getItem("gradeid")).filter(item=>{
          return item.id != id
        })
        localStorage.setItem('gradeid',JSON.stringify(msg));
        this.goods=[];
        this.total=0
        this.requestShopMsg()
      }
    },
    mounted() {
      this.requestShopMsg();
      // console.log(this.$route.params);
      
    },
}
</script>

<style scoped lang='scss'>
  #mine{
    width: 100%;
    height: 100%;
    background: url(/img/minebg.png) no-repeat;
    background-size: contain;
  }

  h1{
    width: 100%;
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-size: 16px;
    font-weight: bold;
  }
  .header{
    width: 100%;
    height: 55px;
    box-sizing: border-box;
    padding: 0 20px;
    display: flex;
    align-items: center;
    margin-top: 10px ;
    .photo{
      width: 55px;
      height: 55px;
    }
    .mess{
      width: 36px;
      height: 31px;
      margin-left: 20px;
    }
    .right{
      width: 200px;
      height: 55px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      margin-left: 12px;
      font-size: 14px;
      color: #333;
      font-weight: bold;
      // p{
      //   margin-bottom: 10px;
      // }
    }
  }

  .sore{
    width: 318px;
    height: 64px;
    margin: 20px auto;
    box-shadow: 0px 0px 3px rgba(153, 153, 153, 0.349019607843137);
    background: white;
    .invite,.jifen{
      width: 159px;
      height: 100%;
      float: left;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      span{
        margin: 6px 0;
        font-size: 11px;
        color: #666;
        i{
          font-size: 16px;
          color: #333;
        }
      }
      
    }
  }

  .about{
    width: 318px;
    height: 85px;
    margin: 12px auto 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0px 0px 3px rgba(153, 153, 153, 0.349019607843137);
    background: white;
    div{
      display: flex;
      flex-direction: column;
      font-size: 11px;
      img{
        width: 45px;
        height: 45px;
        margin-bottom: 5px;
      }
    }
  }
  .show {
    position: absolute;
    bottom: 100px;
    top: 320px;
    width: 100%;
    // padding: 10px 15px;
    box-sizing: border-box;
    background: #f9f9f9;
      li {
        display: flex;
        padding: 10px 20px;
        box-sizing: border-box;
        img {
          width: 90px;
        }
        .introduction {
          display: flex;
          flex-direction: column;
          margin-left: 15px;
          justify-content: space-around;
          position: relative;
          width: 220px;
          p{
              font-size: 14px;
              font-weight: 700;
              color:#515151
          }
          h1{
              height: 25px;
              line-height: 25px;
              width: 70px;
              text-align: center;
              border-radius: 5px;
              border: 1pX solid #FF0000;
              color: #FF0000;
          }
          h2{
              color: #aaa;
              font-size: 12px;
          }
          h3{
              color: #FF0000;
              font-size: 14px;
              font-weight: 700;
          }
          h4{
              position: absolute;
              right: 0;
              bottom: 20px;
              width: 76px;
              height: 27px;
              line-height: 27px;
              font-family: '微软雅黑 Bold', '微软雅黑 Regular', '微软雅黑';
              font-weight: 700;
              font-style: normal;
              font-size: 12px;
              color: #FF0000;
              padding: 0;
              background-color: rgba(255, 235, 232, 1);
              text-align: center;
              border-radius: 8px;
          }
        }
      }
    }
.content{
  height: 100%;
  width: 100%;
  h6{
    margin: 5px auto 0;
    width: 250px;
    height: 30px;
    background:  rgba(254, 155, 122, 1);
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    line-height: 30px;
    color: #fff;
    border-radius: 25px;
  }

}
  h5{
    position: absolute;
    bottom: 50px;
    width: 100%;
    background: #6CC0FE;
    // text-align: center;
    font-size: 15px;
    // font-weight: 600;
    line-height: 50px;
    color: #fff;
    padding: 0 25px;
    box-sizing: border-box;
    span{
      font-weight: 600;
      color: #FF0000;
    }
    i{
      float: right;
      margin-top: 10px;
      height: 30px;
      width: 100px;
      background: #FA7268;
      border-radius: 15px;
      text-align: center;
      line-height: 30px;
    }
  }
</style>